<template>
	<!--pages/extend/index.wxml-->
	<view>
		<cu-custom :bgColor="'bg-'+theme.backgroundColor" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">选择用药人</block>
		</cu-custom>
		<view style="padding-bottom:140rpx">
			<view @tap="getUser(dataList.id)" :data-user='item' 
				class="disease-list bg-white">
				<view>
					<text>{{dataList.userName}}</text>
					<text>{{dataList.idCard}}</text>
				</view>
				<view class="disease-icon">
					<text @tap.stop="changeRuguser(dataList.id)" :data-people='item' class="cuIcon-write"></text>
					<!-- <text @tap="deleteRuguser(item)" :id='index' class="cuIcon-delete"></text> -->
				</view>
			</view>

		</view>
		<view class="add-people">
			<view @tap="addPeople" class="round" v-if="!dataList.id">+新建用药人</view>
		</view>

	</view>
</template>

<script>
	const app = getApp();
	import api from 'utils/api'
	const util = require("utils/util.js");
	export default {
		data() {
			return {
				theme: app.globalData.theme, //全局颜色变量
				dataList: {},
				page: {
					// current: 1,
					// size: 20,
				},
				parameter: {},
				peopleData: {
					a: 1
				}

			};
		},
		mounted() {
			let that = this
			this.getPeopleList()
			uni.$on('people', function(data) {
				that.getPeopleList()
			})
		},
		methods: {
			getPeopleList() {//用药人列表
				api.getMessage().then(res => {
					this.dataList = res.data
					console.log(res,'我是身份列表')
				})
			},
			addPeople() {//去新增
				uni.navigateTo({
					url: '/pages/users/user_personal_list/index'
				})
			},
			changeRuguser(id) {//修改
				uni.navigateTo({
					url: '/pages/users/user_personal_list/index?id=' + id
				})
			},
			deleteRuguser(item) {//删除
				api.delPatientPeople(item.id).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '删除成功',
							duration: 2000,
							icon: "none",
						})
						this.getPeopleList()
					}
				})
			},
			getUser(id) {
				var pages = getCurrentPages(); // 获取页面栈
				var currPage = pages[pages.length - 1]; // 当前页面
				var prevPage = pages[pages.length - 2]; // 上一个页面
				prevPage.$vm.infoMethod(id); //调用上一个页面的 setUserAddress 方法，并传入 userAddressForm
				uni.navigateBack({
					delta: 1
				});
			}

		}

	}
</script>

<style scoped lang="scss">
	.disease-list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10rpx 30rpx;
		margin-top: 20rpx;
	}

	.disease-icon text {
		padding: 16rpx;
		font-size: 36rpx;
	}

	.disease-list>view:nth-child(1) {
		display: flex;
		flex-direction: column;
	}

	.disease-list>view:nth-child(1)>text:nth-child(1) {
		font-size: 30rpx;
		color: var(--black);
	}

	.disease-list>view:nth-child(1)>text:nth-child(2) {
		font-size: 26rpx;
		color: var(--gray);
	}

	.add-people {
		width: 100%;
		padding: 30rpx 0;
		background-color: var(--white);
		position: fixed;
		left: 0;
		bottom: 0;
	}

	.add-people>view {
		width: 680rpx;
		height: 80rpx;
		background-color: #e5432e;
		color: white;
		font-size: 30rpx;
		text-align: center;
		line-height: 80rpx;
		margin: 0 auto;
	}
</style>
